package com.yin.myproject.thread;

/**
 * @author Eason
 * @create 2018-05-14 14:07
 **/
public class Printto75 {
    static class Printer implements Runnable {
        static final int END = 75;
        static int num = 1;
        int id;

        public Printer(int id) {
            this.id = id;
        }

        @Override
        public void run() {
            synchronized (Printer.class) {
                while (num <= END) {
                    if (num / 5 % 3 == id) {
                        System.out.print(id + ":");
                        for (int i = 0; i < 5; i++) {
                            System.out.print(num++ + " ");
                        }
                        System.out.println();
                        Printer.class.notifyAll();
                    }else {
                        try {
                            Printer.class.wait();//如果不属于自己的数，把当前线程挂在Printer.class这个对象的等待队列上（也是放弃CPU使用权），等待唤醒
                        } catch (InterruptedException e) {
                            System.out.println("id" + "被打断了");
                        }
                    }
                }
            }
        }
    }
    public static void main(String[] args) {
        new Thread( new Printer(0)).start();
        new Thread( new Printer(1)).start();
        new Thread( new Printer(2)).start();
    }
}
